import { call, put, takeLatest } from 'redux-saga/effects';
import userService from 'src/service/user/user.service';
import { updateUser } from './user.reducer';

function* getUserInfoAsync() {
  const { data, success } = yield call(userService.getUserInfo);
  if (success) {
    yield put(updateUser(data.userInfo));
  }
}

export const GET_USER_INFO_ASYNC = 'GET_USER_INFO_ASYNC';
export const userSaga = function* () {
  yield takeLatest(GET_USER_INFO_ASYNC, getUserInfoAsync);
};
